#include "mainwindow.h"
#include "ui/hdeviceselect.h"
#include "sniffer/hnetdevice.h"
#include "ui/hcaptureview.h"

#include <QAction>
#include <QMenu>
#include <QToolBar>
#include <QMenuBar>
#include <QSplitter>
#include <QGridLayout>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    m_netDevice = new HNetDevice;
    m_netDevice->initDeviceInfo();

    initMenu();
    initContext();
}

MainWindow::~MainWindow()
{

}

void MainWindow::initMenu()
{
    QAction* selectDeviceAct = new QAction(tr("Select Device"), this);
    //selectDeviceAct->setIcon(QIcon(":/res/images/corporation.png"));
    selectDeviceAct->setShortcut(tr("Ctrl+N"));
    selectDeviceAct->setStatusTip(tr("Select Device"));
    connect(selectDeviceAct, SIGNAL(triggered()), this, SLOT(onSelectDevice()));


    QToolBar* toolBar = this->addToolBar(tr("Capture"));
    toolBar->addAction(selectDeviceAct);
}

void MainWindow::initContext()
{
    QSplitter* mainSplitter = new QSplitter(Qt::Vertical);
    setCentralWidget(mainSplitter);

    m_captureView = new HCaptureView;
    mainSplitter->addWidget(m_captureView);

    QWidget* bottomWidget = new QWidget;
    mainSplitter->addWidget(bottomWidget);

    QVBoxLayout* vlayout = new QVBoxLayout(bottomWidget);
    QSplitter* bottomSplitter = new QSplitter(Qt::Horizontal);
    vlayout->addWidget(bottomSplitter);
}

void MainWindow::onSelectDevice()
{
    HDeviceSelectDlg* dlg = new HDeviceSelectDlg(this);
    dlg->initData(m_netDevice->deviceInfo());
    dlg->exec();
}
